/***************************************************************************
 *   Copyright (C) 2008 by Eduardo Gurgel Pinho                            *
 *   edgurgel@gmail.com                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#include "vector_widget.h"

#include <QHBoxLayout>
#include <QDoubleSpinBox>

namespace Ui {
	
Vector_Widget::Vector_Widget(QWidget* _parent) : QWidget(_parent) { 
	
	QHBoxLayout* hboxlayout = new QHBoxLayout();
	x_value = new QDoubleSpinBox(this);
	y_value = new QDoubleSpinBox(this);
	z_value = new QDoubleSpinBox(this);
	
	hboxlayout->addWidget(x_value);
	hboxlayout->addWidget(y_value);
	hboxlayout->addWidget(z_value);
	hboxlayout->addStretch();
	
	setLayout(hboxlayout);
	
	connect(x_value,SIGNAL(valueChanged(double)),this,SLOT(x_change_value(double)));
	connect(y_value,SIGNAL(valueChanged(double)),this,SLOT(y_change_value(double)));
	connect(z_value,SIGNAL(valueChanged(double)),this,SLOT(z_change_value(double)));
}

Vector_Widget::~Vector_Widget(void) { }

void Vector_Widget::set_vector(const Sirat::Math::Vector& _vector) {
	vector = _vector;
	x_value->setValue(vector.x);
	y_value->setValue(vector.y);
	z_value->setValue(vector.z);
}

Sirat::Math::Vector Vector_Widget::get_vector(void) const {
	return vector;
}

void Vector_Widget::x_change_value(double _x) {
	vector.x = _x;
	emit vector_updated();
}

void Vector_Widget::y_change_value(double _y) {
	vector.y = _y;
	emit vector_updated();
}

void Vector_Widget::z_change_value(double _z) {
	vector.z = _z;
	emit vector_updated();
}


}

